<template>
    <div>
		<van-nav-bar left-text="返回" title="手机登录" left-arrow @click-left="onClickLeft" />
		<van-form>
			<van-cell-group inset>
				<van-field
					v-model="phone"
					name="phone"
					label="手机"
					placeholder="请输入手机号"
					:rules="[{ required: true, message: '请填写手机号' }]"
				/>
				<van-field
					v-model="password"
					type="password"
					name="password"
					label="密码"
					placeholder="密码"
					:rules="[{ required: true, message: '请填写密码' }]"
				/>
			</van-cell-group>
			<div style="margin: 16px">
				<van-button @click="onSubmit" round block color="linear-gradient(to right, #ff6034, #ee0a24)"> 登录 </van-button>
			</div>
		</van-form>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { RequestPsLogin } from "@/api/user"
import { Notify } from 'vant'
import router from '@/router'
import { useuidStore } from '@/stores/user'
const userstore = useuidStore()

const phone = ref('17745056078')
const password = ref('')

const onSubmit = async () => {
	const res = await RequestPsLogin (phone.value,password.value)
	console.log(res)
	if(res.data.code == 200){
		Notify({type:"success",message:"登录成功"})
		userstore.saveUser(res.data.profile.userId,res.data.profile.avatarUrl,res.data.profile.nickname)
		router.push({path:'/home'})
	}else{
		Notify({type:"danger",message:"登录失败"})
	}
}

const onClickLeft = () => {
	history.back()
}
</script>

<style scoped>

</style>